package com.example.demo.compent;

import com.example.demo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.net.PortUnreachableException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2024-03-01
 * Time: 21:51
 */
@Component
public class BeanLifeComponent {

    private User singleUser;

    public BeanLifeComponent(){
        System.out.println("执行构造方法");
    }

    @Autowired
    public void setUser(User singleUser){
        this.singleUser = singleUser;
        System.out.println("属性注入");
    }

    @PostConstruct
    public void init(){
        System.out.println("执行初始化方法");
    }

    public void use(){
        System.out.println("执行use方法");
    }

    @PreDestroy
    public void destroy(){
        System.out.println("执行销毁任务");
    }
}
